import pagination from '@/views/pagination' //分页组件
import agentHttp from '@/utils/agentHttp.js' //引用JS
import exportExcel from '@/utils/exportExcel' //导出
import edit from './edit';
import {
  debounce,
  setEndDateTime
} from '@/utils/index.js'
import { dirname } from 'path';

export default {
  components: {
    pagination,edit
  },
  created() { //初始化
    this.seachData();
    this.getCarOrderStatusMap();
  },
  data() { //初始化数据
    return {
      //弹窗状态数据
      dialogSendData: {
        isAdd: "",
        dialogFormVisible: "",
        id: ""
      },
      //表格字段
      tableData: [],
      //搜索字段
      searchForm: {
        dealerName: "",
        carBrandNameAndCarName: "",
        orderNumber: "",
        startDate: "",
        endDate: "",
        logisticsInfoStatus: "",        //物流状态
        carInspectionInfoStatus: "",    //验车状态
        depositInfoStatus: "",              //保证经状态  
        status: "",                    //订单状态
      },
      orderTypeMap:[],
      logisticsStatusMap:[],
      cashDepositStatusMap:[],
      carInspectionStatusMap:[],
      //用于时间选择控制
      startDateOpt: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      },
      endDateOpt: {
        disabledDate: (time) => {
          return time.getTime() < new Date(this.searchForm.startDate).getTime();
        }
      },
      multipleSelection: []
    }
  },
  methods: { //所有方法
    handleSee(code, row) {
      code=='查看'? this.dialogSendData.isAdd = false:this.dialogSendData.isAdd = true;
      this.dialogSendData.id = row.id 
      this.dialogSendData.dialogFormVisible = true;
    },
    //数据流方式导出
    exportExcels(searchForm, url, name) {
      exportExcel(searchForm, url, name)
    },


    //列表查询
    seachData() {
      var params = this.searchForm || {};
      params.page = this.tableData.page || 1;
      params.rows = this.tableData.rows || 10;
      agentHttp.postJson(`adminApi/admin/car_order_cancel/list?page=${params.page}&rows=${params.rows}`, params).then((data) => {
        this.tableData = data
        this.multipleSelection = data.data;
      })

    },
    //延迟搜索
    debounceSeach() {
      this.tableData.page = 1;
      debounce(this.seachData(), 1000)
    },
    //重置
    resetSearchForm(formName) {
      //   this.resetFormStatus=true;
      this.tableData.page = 1;
      this.tableData.rows = 10;
      this.$refs[formName].resetFields();
      this.$nextTick(_ => {
        // this.resetFormStatus=false;
        this.seachData();
      })
    },
    //获取订单状态
    getCarOrderStatusMap() {
      agentHttp.get('adminApi/admin/car_order_cancel/get_status_map').then((data) => {
        if (data.success) {
            this.orderTypeMap = data.data.orderStatus;
            this.logisticsStatusMap = data.data.logisticsStatus;
            this.cashDepositStatusMap = data.data.cashDepositStatus;
            this.carInspectionStatusMap = data.data.carInspectionStatus;
        }
      })
    },

  }
}